home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Games Collection 1 / software vault.zip / software vault / CDR10 / SPX20.ZIP / SPX_DOC.ZIP / SPX_CRD.DOC < prev    next >
Text File  |  1993-08-17  |  5KB  |  196 lines

  1. Unit spx_crd;
  2.  
  3. {$X+,O+ }
  4. { SPX Library Version 2.0  Copyright 1993 Scott D. Ramsay }
  5.  
  6. { SPX_CRD contains simple playing card handling routines for BlackJack 21 and Poker
  7.   Cards and Decks are defined as follows:
  8.  
  9.   Tcard         = record
  10.                    card,suite : byte;
  11.                   end;
  12.   Tdeck         = array[0..51] of Tcard;
  13.  
  14.   Tcard.card contains the card value where CARD=2 is the card 2, CARD=4 is the card 4, etc.
  15.              Jack=11, Queen=12, etc.  See constant declarations below:
  16.  
  17.   Tcard.suite contains the suit of each card. Where: diamond=0, heart=1, spade=2, club=3
  18.  
  19.   Tdeck is an array the defines a standard deck of 52 cards.
  20.  
  21. }
  22.  
  23.  
  24. Interface
  25.  
  26. const
  27.  { card value type }
  28.   crd_jack    = 11;
  29.   crd_queen   = 12;
  30.   crd_king    = 13;
  31.   crd_ace     = 14;
  32.  { card suite type }
  33.   crd_diamond = 0;
  34.   crd_heart   = 1;
  35.   crd_spade   = 2;
  36.   crd_club    = 3;
  37.  { five card poker values }
  38.   crd_nothing    = 0;           { nothing of value }
  39.   crd_onepair    = 1;           { one of a kind }
  40.   crd_twopair    = 2;           { two of a kind }
  41.   crd_threekind  = 3;           { three of a kind }
  42.   crd_fourkind   = 4;           { four of a kind }
  43.   crd_fullhouse  = 5;           { full house }
  44.   crd_straight   = 6;           { straight }
  45.   crd_flush      = 7;           { flush }
  46.   crd_straightf  = 8;           { straight flush }
  47.   crd_rstraightf = 9;           { royal straight flush }
  48.  
  49. type
  50.  { values returned by BJ_Dealer }
  51.   BlackJackType = (BJnothing,BJhit,BJstay,BJsplit,BJdouble);
  52.  { Card definitions }
  53.   Tcard         = record
  54.                     card,suite : byte;
  55.                   end;
  56.   Tdeck         = array[0..51] of Tcard;
  57.  
  58. { contains the highest card in hand after call from PokerHand }
  59.  
  60. var
  61.   hicard : Tcard;
  62.  
  63.  
  64.  
  65. {-----------------------------------------------------------}
  66. procedure SwapCard(var card1,card2:Tcard);
  67.  
  68.   Exchanges two cards:   e.g.
  69.  
  70.   card1, card2  : Tcards to exchange
  71.  
  72. {-----------------------------------------------------------}
  73. procedure CreateDeck(var adeck:Tdeck);
  74.  
  75.   Fills a deck with the standard card values. (sorted)
  76.  
  77.   adeck  :  The deck to be sorted
  78.  
  79. {-----------------------------------------------------------}
  80. procedure ShuffleDeck(var adeck:Tdeck);
  81.  
  82.   Randomly shuffles a deck
  83.  
  84.   adeck  : The deck to be shuffled
  85.  
  86. {-----------------------------------------------------------}
  87. procedure SortDeck(var adeck;Lo,Hi:integer);
  88.  
  89.   Sorts a deck or a portion of a deck.
  90.  
  91.   adeck   : The deck or a players hand to be sorted
  92.   Lo      : The low card to be sorted
  93.   Hi      : The high card to be sorted
  94.  
  95.   adeck is an untyped variable so one can pass in the players hand. eg.
  96.  
  97.      Var
  98.         TheDeck : Tdeck;
  99.         MyHand  : array[0..4] of Tcard;
  100.         .
  101.         .
  102.         .
  103.  
  104.      SortDeck(TheDeck,1,52);     { Sort the entire deck }
  105.      SortDeck(TheDeck,10,24);    { Sort the cards starting at 10 to 24 }
  106.      SortDeck(MyHand,1,5);       { Sort MyHand (0..4) -> 1..5 }
  107.  
  108.   NOTE:  Note that the first card passed in is always 1 not 0.
  109.  
  110. {-----------------------------------------------------------}
  111. function PokerHand(var ahand):integer;
  112.  
  113.   Evaluates a five card poker hand and returns the hand value.
  114.  
  115.   ahand :  array [0..4] of Tcard to evaluate
  116.  
  117.   Returns one of the following values
  118.  
  119.       crd_nothing
  120.       crd_onepair
  121.       crd_twopair
  122.       crd_threekind
  123.       crd_fourkind
  124.       crd_fullhouse
  125.       crd_straight
  126.       crd_flush
  127.       crd_straightf
  128.       crd_rstraightf
  129.  
  130.   Also sets the variable HICARD to the highest value card in the hand.
  131.  
  132. {-----------------------------------------------------------}
  133. function SuiteString(suite:byte):string;
  134.  
  135.   Returns a string of the suite name.
  136.  
  137.   example:
  138.  
  139.     writeln('The suit you picked is ',SuiteString(crd_heart));
  140.  
  141. {-----------------------------------------------------------}
  142. function PokerHandString(ehandvalue:integer):string;
  143.  
  144.   Returns a string of the poker hand name.
  145.  
  146.   ehandvalue :  poker hand value
  147.  
  148.  
  149.   example:
  150.  
  151.   var
  152.     MyHand : array[0..4] of Tcard;
  153.  
  154.   writeln('You have: ',PokerHandString(PokerHand(MyHand)));
  155.  
  156. {-----------------------------------------------------------}
  157. function BJ_Total(var ahand;cards:integer):integer;
  158.  
  159.  Evaluates the highest value a BlackJack hand can contain.  Returns the hand value.
  160.  
  161.  automatically converts ACES to 11 or 1 depending which is better
  162.  
  163.  
  164.  ahand    : Cards to evaluate
  165.  cards    : Number of cards in ahand
  166.  
  167.  example:
  168.  
  169.     var
  170.       MyHand : array[0..4] of Tcard;
  171.  
  172.     ncards := 3;
  173.     value := BJ_Total(MyHand,ncards);
  174.     if value>21
  175.       then writeln('You are busted')
  176.       else
  177.     if (value=21) and (ncards=2)
  178.       then writeln('You got BlackJack!!!')
  179.       else writeln('You got ',value);
  180.  
  181. {-----------------------------------------------------------}
  182. function BJ_Dealer(var ahand;cards:integer):BlackJackType;
  183.  
  184.  Returns a value what the dealer would do for the next card.
  185.  
  186.  ahand   : Cards to evaluate
  187.  cards   : Number of cards
  188.  
  189.  Returns one of the following values:
  190.  
  191.      BJnothing
  192.      BJhit
  193.      BJstay
  194.  
  195. {-----------------------------------------------------------}
  196.